import { CustomRequestFieldElement } from "./CustomRequestFieldElement.js";
import { EnumRequestFieldElement } from "./EnumRequestFieldElement.js";
import type { IRequestFieldElement } from "./IFieldElement.js";
import { ListRequestFieldElement } from "./ListRequestFieldElement.js";
import { NumberRequestFieldElement } from "./NumberRequestFieldElement.js";
import type {
    ListRequestFieldOption,
    NumberRequestFieldOption,
    RequestFieldOption,
    StringRequestFieldOption,
} from "./RequestOption.js";
import { StringRequestFieldElement } from "./StringRequestFieldElement.js";

function createString(option: StringRequestFieldOption): IRequestFieldElement {
    const group = new StringRequestFieldElement();
    group.classList.add("group");
    group.option = option;
    return group;
}

function createNumber(option: NumberRequestFieldOption): IRequestFieldElement {
    const group = new NumberRequestFieldElement();
    group.classList.add("group");
    group.option = option;

    return group;
}

function createList(option: ListRequestFieldOption): IRequestFieldElement {
    const group = new ListRequestFieldElement();
    group.classList.add("group");
    group.option = option;

    return group;
}

export function createOption(option: RequestFieldOption): IRequestFieldElement {
    switch (option.kind) {
        case "string":
            return createString(option);
        case "list":
            return createList(option);
        case "custom": {
            const group = new CustomRequestFieldElement();
            group.classList.add("group");
            group.option = option;
            return group;
        }
        case "enum": {
            const group = new EnumRequestFieldElement();
            group.classList.add("group");
            group.option = option;
            return group;
        }
        default:
            return createNumber(option);
    }
}
